//
//  ViewController.m
//  自定义空间
//
//  Created by MyMac on 15/7/15.
//  Copyright (c) 2015年 MyMac. All rights reserved.
//

#import "ViewController.h"
#import "CustomControl.h"
#define TB_BACKGROUND_WIDTH 25.0f
#define radius self.frame.size.height/2-TB_BACKGROUND_WIDTH/2
#define TB_LINE_WIDTH TB_BACKGROUND_WIDTH-5.0f
#define MinDistance MIN(200, 150)
#define ToRad(deg) 		( (M_PI * (deg)) / 180.0 )//旋转的角度
#define ToDeg(rad)		( (180.0 * (rad)) / M_PI )
#define SQR(x)			( (x) * (x) )
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CustomControl*custom=[[CustomControl alloc]initWithFrame:CGRectMake(100, 100, 150, 150)];
    custom.angle=360.0;
    
    custom.backgroundColor=[UIColor yellowColor];
    [self.view addSubview:custom];
    CGImageRef  imageRef=[self receiveCurrentImage];
    self.imageView.image=[UIImage imageWithCGImage:imageRef];
    [custom addTarget:self action:@selector(cusEvent:) forControlEvents:UIControlEventValueChanged];
    
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)cusEvent:(CustomControl*)cus
{

    NSLog(@"方法被调用");



}
-(CGImageRef)receiveCurrentImage
{
    UIGraphicsBeginImageContext(CGSizeMake(320,320));
    
    CGContextRef imageCtx = UIGraphicsGetCurrentContext();
    CGContextAddArc(imageCtx,MinDistance/2.0,MinDistance/2.0,MinDistance/2.0-TB_LINE_WIDTH/2.0, 0,ToRad(360),0);
    
    [[UIColor redColor]set];
    
    //设置阴影，，，显示模糊效果
    CGContextSetShadowWithColor(imageCtx, CGSizeMake(0, 0), 360/20, [UIColor blackColor].CGColor);
    
    //define the path
    CGContextSetLineWidth(imageCtx, TB_LINE_WIDTH);
    CGContextDrawPath(imageCtx, kCGPathStroke);
    
    //save the context content into the image mask
    CGImageRef mask = CGBitmapContextCreateImage(imageCtx);
    //UIImage*image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //CGImageRelease(mask);
    return mask;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
